
<link rel="stylesheet" href="php-txt-db-api.css" type="text/css">

<title>PHP: Text File Database Manual</title><div align="center">
  <h1 align="left"> Design / Structure of the Databases</h1>
  <p align="left">Each Database is represented by a Directory. A Database has 
    the same name as the Directory.<br>
    All Database-Directories have to be in the same Directory, and this Directory 
    (the one containing all Database Directories)<br>
    is set with the Setting $DB_DIR in the file txt-db-api.php.</p>
  <p align="left"><b>Small Example:</b></p>
  <p align="left">$DB_DIR is set to &quot;/home/websites/myhome/Databases/&quot;. 
    <br>
    So you can have 1 or More Database (=&gt; Database Folders) under /home/websites/myhome/Databases/.<br>
    If you want a Database called MyDb, it will be located in /home/websites/myhome/Databases/MyDb.<br>
    If you want a second Database called MySecondDB, it will be located in /home/websites/myhome/Databases/MySecondDB....<br>
    I recommend you to add a .htaccess File to each Database folder or the .txt 
    files in any folders that can be directly <br>
    read trough a browser (i.e. especially if the name is known).</p>
  <p align="left">$DB_DIR can also be set to a Windows Path of course, like C:\myWeb\bla\Databases\</p>
  <p align="left"> Now if you want to execute a SQL-Statements on the Database 
    MyDb you have to<br>
    create a Database-Object first. For example:</p>
  <p align="left">$db=new Database(&quot;MyDb&quot;);</p>
  <p align="left">The argument in the constructor is the name (i.e. folder) 
    of the database relative to the $DB_DIR directory.</p>
  <p align="left"><b>ATTENTION: </b>Database names are case sensitive</p>
  <p align="left">Now if you have a Database instance ($db) you can execute some 
    SQL Statements.<br>
    For example, to create a table :</p>
  <div align="left">
    <pre>$db-&gt;executeQuery(&quot;CREATE TABLE people (nr inc, name str, surname str, age int)&quot;);

</pre>
    <p>You can also create Tables <a href="examples/tut2.html">manualy</a>.</p>
    <p>Tables are stored as .txt Files in the Database Directory. But this is 
      not so important, if you wish you can do everything with API calls without 
      ever touching the .txt Files.</p>
    <p>Only one thing is very important: All databases are really folders which 
      must all be locatet in $DB_DIR!</p>
    <p><b>IMPORTANT</b>: The Database Directories must be create via FTP, and 
      do not forgett to do a chmod() <br>
      on the directory or the CREATE TABLE calls will fail!</p>
    </div>
  <p align="left">&nbsp;</p>
  <p align="left"><b>Another example:</b></p>
  <p align="left">The Website-Root is under /home/website/myPage/</p>
  <p align="left">The API Files are under /home/website/myPage/txt-db-api/</p>
  <p align="left">The Directory containing the Databases is /home/website/myPage/Databases</p>
  <p align="left">Two Databases are installed named TestDB and ProdDB, therefore, the following directories exist:<br>
  </p>
  <p align="left">/home/website/myPage/Databases/TestDB/<br>
    and<br>
    /home/website/myPage/Databases/ProdDB/</p>
  <p align="left">The rights to these folders where changed with chmod() (i.e. 
    to 777 or something permitting write access).</p>
  <p align="left">For this Directory-Structures the Settings in the txt-db-api.php 
    would look like this:</p>
  <div align="left"> 
    <pre align="left">$API_HOME_DIR="/home/website/myPage/txt-db-api/"; 
$DB_DIR="/home/website/myPage/Databases/"; 
</pre>
    <p><br>
      A php script in the Directory /home/website/myPage/ would start like:</p>
    <pre>&lt;? php</pre>
    <pre>include(&quot;txt-db-api/txt-db-api.php&quot;);
.....
     </pre>
  </div>
</div>
